<!DOCTYPE html>
<html xmlns:th="http://www.springframework.org/schema/mvc">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="visitUrl">访问</a>
</script>


<script src="/static/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script th:inline="none">
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#test',
            url: '/rest/test/table',
            defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            title: '用户数据表',
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {
                    field: 'id',
                    title: '编号',
                    sort: true
                },
                {
                    field: 'tagName',
                    title: '标签',
                    edit: 'text'
                },
                {
                    field: 'linkName',
                    title: '网站',
                    edit: 'text',
                },

                {
                    field: 'color',
                    title: '级别',
                },
                {
                    fixed: 'right',
                    title: '操作',
                    toolbar: '#barDemo',
                }
            ]],
            page: false
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.prompt({
                    formType: 2
                    , value: data.linkUrl
                }, function (value, index) {
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'visitUrl') {
                window.open(data.linkUrl, "_blank");
            }
        });
    });
</script>

</body>
</html>